export default {
    data() {
        return {
            data: [],
            more: true,
            status: 'loadmore',
            pageNum: 1,
            pageSize: 10
        };
    },
    methods: {
        onRefresh() {
            this.status = 'loadmore';
            this.pageNum = 1;
            this.more = true;
            this.data = [];
            this.getData();
        },
        async getData() {
            this.status = 'loading';
            let { data: { list, total } } = await this.onRequest();
            if (this.formatData) {
                list = this.formatData(list);
            }
            this.data = this.data.concat(list);
            this.pageNum++;
            this.more = total > this.data.length;
            if (!this.more) {
                this.status = 'nomore';
            }
        }
    },
    onPullDownRefresh() {
        this.onRefresh();
    },
    onReachBottom() {
        this.more && this.getData();
    }
};
